/**
 * 通知公告管理初始化
 */
var Announcement = {
    id: "AnnouncementTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Announcement.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '标题', field: 'noticeTitle', visible: true, align: 'center', valign: 'middle'},
        {title: '作者', field: 'author', visible: true, align: 'center', valign: 'middle'},
        {title: '状态', field: 'statusName', visible: true, align: 'center', valign: 'middle'},
        //{title: '通知内容', field: 'noticeContent', visible: true, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Announcement.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Announcement.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加通知公告
 */
Announcement.openAddAnnouncement = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['950px', '600px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/announcement/announcement_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看通知公告详情
 */
Announcement.openAnnouncementDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['950px', '600px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/announcement/announcement_update/' + Announcement.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 打开查看通知公告详情
 */
Announcement.openDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['950px', '600px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/announcement/announcement_detail/' + Announcement.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除通知公告
 */
Announcement.delete = function () {


    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/announcement/delete", function (data) {
                Feng.success("删除成功!");
                Announcement.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("announcementId", Announcement.seItem.id);
            ajax.start();
        };
        Feng.confirm("是否刪除?", operation);
    }
};

Announcement.doCheck = function () {


    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/announcement/check", function (data) {
                Feng.success("审核通过!");
                Announcement.table.refresh();
            }, function (data) {
                Feng.error("审核失败!" + data.responseJSON.message + "!");
            });
            ajax.set("announcementId", Announcement.seItem.id);
            ajax.start();
        };
        Feng.confirm("是否通过审核?", operation);
    }
};


Announcement.doReject = function () {


    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/announcement/reject", function (data) {
                Feng.success("驳回成功!");
                Announcement.table.refresh();
            }, function (data) {
                Feng.error("驳回失败!" + data.responseJSON.message + "!");
            });
            ajax.set("announcementId", Announcement.seItem.id);
            ajax.start();
        };
        Feng.confirm("是否驳回审核?", operation);
    }
};

/**
 * 查询通知公告列表
 */
Announcement.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Announcement.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Announcement.initColumn();
    var table = new BSTable(Announcement.id, "/announcement/list", defaultColunms);
    table.setPaginationType("client");
    Announcement.table = table.init();
});
